#!/bin/sh
set -o errexit

# sudo apt-get remove docker docker-engine docker.io docker-ce 
sudo apt-get update
sudo apt-get install -y docker.io
systemctl start docker
systemctl enable docker
sudo docker version

# 检查 docker 组是否存在
if ! getent group docker > /dev/null 2>&1; then
    # 如果不存在，则创建 docker 组
    sudo groupadd docker
    sudo gpasswd -a ${USER} docker
    echo "docker 组已成功创建。"
    
    sudo service docker restart
    systemctl enable docker.service

    echo "[log] new group: docker"
    newgrp - docker
else
    echo "docker 组已存在。"
fi

echo "[log] cp docker-compose"
sudo cp docker-compose /usr/local/bin/docker-compose

echo "[log] chmod docker-compose"
sudo chmod +x /usr/local/bin/docker-compose

